<template>
  <div style="display: none;">
    <!-- 这是一个纯逻辑组件，不需要模板内容 -->
  </div>
</template>

<script>
import { Message, MessageBox, Notification } from 'element-ui'

export default {
  name: 'MessageBox',
  data() {
    return {
      messageInstance: null
    }
  },
  methods: {
    // 成功提示
    success(message, options = {}) {
      const defaultOptions = {
        duration: 3000,
        type: 'success',
        customClass: 'custom-message'
      }
      return Message(Object.assign(defaultOptions, options, { message }))
    },

    // 错误提示
    error(message, options = {}) {
      const defaultOptions = {
        duration: 5000,
        type: 'error',
        customClass: 'custom-message'
      }
      return Message(Object.assign(defaultOptions, options, { message }))
    },

    // 警告提示
    warning(message, options = {}) {
      const defaultOptions = {
        duration: 4000,
        type: 'warning',
        customClass: 'custom-message'
      }
      return Message(Object.assign(defaultOptions, options, { message }))
    },

    // 信息提示
    info(message, options = {}) {
      const defaultOptions = {
        duration: 3000,
        type: 'info',
        customClass: 'custom-message'
      }
      return Message(Object.assign(defaultOptions, options, { message }))
    },

    // 确认对话框
    confirm(message, title = '提示', options = {}) {
      const defaultOptions = {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        customClass: 'custom-message-box'
      }
      return MessageBox.confirm(message, title, Object.assign(defaultOptions, options))
    },

    // 删除确认对话框
    deleteConfirm(message = '确定要删除这条记录吗？', options = {}) {
      const defaultOptions = {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        message: message,
        customClass: 'custom-message-box'
      }
      return MessageBox.confirm(message, '删除确认', Object.assign(defaultOptions, options))
    },

    // 输入对话框
    prompt(message, title = '提示', options = {}) {
      const defaultOptions = {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputPattern: /.+/,
        inputErrorMessage: '不能为空',
        customClass: 'custom-message-box'
      }
      return MessageBox.prompt(message, title, Object.assign(defaultOptions, options))
    },

    // 通知提示
    notify(message, title = '通知', options = {}) {
      const defaultOptions = {
        duration: 4500,
        type: 'info',
        customClass: 'custom-notification'
      }
      return Notification(Object.assign(defaultOptions, options, { message, title }))
    },

    // 成功通知
    notifySuccess(message, title = '成功', options = {}) {
      return this.notify(message, title, Object.assign(options, { type: 'success' }))
    },

    // 错误通知
    notifyError(message, title = '错误', options = {}) {
      return this.notify(message, title, Object.assign(options, { type: 'error' }))
    },

    // 警告通知
    notifyWarning(message, title = '警告', options = {}) {
      return this.notify(message, title, Object.assign(options, { type: 'warning' }))
    },

    // 关闭所有消息
    closeAll() {
      Message.closeAll()
      Notification.closeAll()
    }
  }
}
</script>

<style lang="scss">
/* 全局样式 */
body {
  .custom-message {
    min-width: auto;
    width: auto;
    padding: 10px 15px;
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    
    .el-message__content {
      font-size: 14px;
    }
  }
  
  .custom-message-box {
    width: auto;
    min-width: 300px;
    max-width: 80%;
  }
  
  .custom-notification {
    width: auto;
    min-width: 280px;
    max-width: 400px;
  }
}
</style> 